
#include <ttg/libs.h>
#include <tbb/task_scheduler_init.h>

#include "serialHashing.h"
#include "ttgHashing.h"
#include "tbbHashing.h"

int main()
{
	//Initing
	ttg::services::ServiceBase::getRef()->start();
	tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
	printf("TBB vs TTG: FileHashing\n");
	printf("CPU type: %s\n\n", ttg::services::CPUAnalyzer::getRef()->getCPUInfo());
	//Preparing file
	printf("Creating test file ...\n");
	TempFile temp(16 * 1024 * 1024);
	if (temp.getFileName() == NULL)
	{
		printf("Error: cannot create file\n");
		return 0;
	}
	//Serial hashing.
	printf("Calculating using serial version ...\n");
	std::pair<unsigned __int64, double> serialResult = serialHashing(temp);
	printf("Elapsed %f seconds\n", serialResult.second);
	//Parallel hashing (via ttg).
	printf("Calculating using parallel version (via ttg) ...\n");
	std::pair<unsigned __int64, double> ttgResult = ttgHashing(temp);
	printf("Elapsed %f seconds\n", ttgResult.second);
	if (serialResult.first != ttgResult.first)
		printf("Warning! Wrong results: serial == %ld, ttg == %ld\n", serialResult.first, ttgResult.first);
	//Parallel hashing (via tbb).
	printf("Calculating using parallel version (via tbb) ...\n");
	std::pair<unsigned __int64, double> tbbResult = tbbHashing(temp);
	printf("Elapsed %f seconds\n", tbbResult.second);
	if (serialResult.first != tbbResult.first)
		printf("Warning! Wrong results: serial == %ld, tbb == %ld\n", serialResult.first, tbbResult.first);
	return 0;
}
